home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / A Conway's214326202001.psc / Conway / Conway.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-06-19  |  17.9 KB  |  541 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
  4. Begin VB.Form Form1 
  5.    BackColor       =   &H00000000&
  6.    BorderStyle     =   1  'Fixed Single
  7.    Caption         =   "Conway's Game of LIFE"
  8.    ClientHeight    =   10080
  9.    ClientLeft      =   45
  10.    ClientTop       =   360
  11.    ClientWidth     =   13080
  12.    ForeColor       =   &H00FFFFFF&
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   672
  16.    ScaleLeft       =   -436
  17.    ScaleMode       =   0  'User
  18.    ScaleTop        =   -336
  19.    ScaleWidth      =   872
  20.    StartUpPosition =   2  'CenterScreen
  21.    Begin MSComDlg.CommonDialog SaveDialog 
  22.       Left            =   10650
  23.       Top             =   9150
  24.       _ExtentX        =   847
  25.       _ExtentY        =   847
  26.       _Version        =   393216
  27.       Filter          =   "Life files(*.lif)"
  28.    End
  29.    Begin MSComDlg.CommonDialog Dialog 
  30.       Left            =   11220
  31.       Top             =   9150
  32.       _ExtentX        =   847
  33.       _ExtentY        =   847
  34.       _Version        =   393216
  35.       Filter          =   "Life files(*.lif)|*.lif"
  36.    End
  37.    Begin ComctlLib.StatusBar Bar1 
  38.       Align           =   2  'Align Bottom
  39.       Height          =   240
  40.       Left            =   0
  41.       TabIndex        =   9
  42.       Top             =   9840
  43.       Width           =   13080
  44.       _ExtentX        =   23072
  45.       _ExtentY        =   423
  46.       Style           =   1
  47.       SimpleText      =   ""
  48.       _Version        =   327682
  49.       BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
  50.          NumPanels       =   1
  51.          BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  52.             Key             =   ""
  53.             Object.Tag             =   ""
  54.          EndProperty
  55.       EndProperty
  56.    End
  57.    Begin VB.Frame Frame1 
  58.       Height          =   9930
  59.       Left            =   12165
  60.       TabIndex        =   0
  61.       Top             =   -90
  62.       Width           =   915
  63.       Begin VB.CommandButton Command6 
  64.          Caption         =   "Editor"
  65.          Height          =   270
  66.          Left            =   90
  67.          TabIndex        =   16
  68.          Top             =   780
  69.          Width           =   720
  70.       End
  71.       Begin VB.CommandButton Command5 
  72.          Caption         =   "About"
  73.          Height          =   270
  74.          Left            =   90
  75.          TabIndex        =   15
  76.          Top             =   6045
  77.          Width           =   720
  78.       End
  79.       Begin VB.CommandButton Command4 
  80.          Caption         =   "Tip of all days"
  81.          Height          =   435
  82.          Left            =   90
  83.          TabIndex        =   14
  84.          Top             =   9390
  85.          Width           =   720
  86.       End
  87.       Begin VB.CommandButton Command2 
  88.          Caption         =   "Save"
  89.          Height          =   270
  90.          Left            =   90
  91.          TabIndex        =   13
  92.          Top             =   1095
  93.          Width           =   720
  94.       End
  95.       Begin VB.Frame Frame2 
  96.          Caption         =   "Zoom"
  97.          Height          =   855
  98.          Left            =   135
  99.          TabIndex        =   10
  100.          Top             =   3405
  101.          Width           =   645
  102.          Begin VB.OptionButton Option2 
  103.             Caption         =   "x 2"
  104.             Height          =   285
  105.             Left            =   60
  106.             TabIndex        =   12
  107.             Top             =   480
  108.             Width           =   555
  109.          End
  110.          Begin VB.OptionButton Option1 
  111.             Caption         =   "x 1"
  112.             Height          =   285
  113.             Left            =   60
  114.             TabIndex        =   11
  115.             Top             =   210
  116.             Width           =   555
  117.          End
  118.       End
  119.       Begin VB.CommandButton cmdStop 
  120.          Caption         =   "Stop"
  121.          Height          =   270
  122.          Left            =   90
  123.          TabIndex        =   8
  124.          Top             =   5610
  125.          Width           =   720
  126.       End
  127.       Begin VB.CommandButton Command3 
  128.          Caption         =   "Load"
  129.          Height          =   270
  130.          Left            =   90
  131.          TabIndex        =   7
  132.          Top             =   465
  133.          Width           =   720
  134.       End
  135.       Begin VB.CommandButton cmdRefresh 
  136.          Caption         =   "Refresh"
  137.          Height          =   270
  138.          Left            =   90
  139.          TabIndex        =   3
  140.          Top             =   1410
  141.          Width           =   720
  142.       End
  143.       Begin VB.TextBox Text1 
  144.          BeginProperty Font 
  145.             Name            =   "MS Sans Serif"
  146.             Size            =   9.75
  147.             Charset         =   0
  148.             Weight          =   400
  149.             Underline       =   0   'False
  150.             Italic          =   0   'False
  151.             Strikethrough   =   0   'False
  152.          EndProperty
  153.          Height          =   360
  154.          Left            =   90
  155.          TabIndex        =   2
  156.          Top             =   1995
  157.          Width           =   705
  158.       End
  159.       Begin VB.CommandButton Command1 
  160.          Caption         =   "Start"
  161.          Height          =   270
  162.          Left            =   90
  163.          TabIndex        =   1
  164.          Top             =   150
  165.          Width           =   720
  166.       End
  167.       Begin VB.Label Label3 
  168.          AutoSize        =   -1  'True
  169.          Caption         =   "Gen. nr."
  170.          Height          =   195
  171.          Left            =   135
  172.          TabIndex        =   6
  173.          Top             =   1800
  174.          Width           =   645
  175.       End
  176.       Begin VB.Label Label2 
  177.          AutoSize        =   -1  'True
  178.          Caption         =   "Nr. of cells"
  179.          Height          =   195
  180.          Left            =   15
  181.          TabIndex        =   5
  182.          Top             =   2595
  183.          Width           =   765
  184.       End
  185.       Begin VB.Label Label1 
  186.          BorderStyle     =   1  'Fixed Single
  187.          Height          =   345
  188.          Left            =   90
  189.          TabIndex        =   4
  190.          Top             =   2850
  191.          Width           =   705
  192.       End
  193.    End
  194. Attribute VB_Name = "Form1"
  195. Attribute VB_GlobalNameSpace = False
  196. Attribute VB_Creatable = False
  197. Attribute VB_PredeclaredId = True
  198. Attribute VB_Exposed = False
  199. Option Explicit
  200. Dim drawcell As Byte, xx As Long, yy As Long, oriz As Long, vert As Long
  201. Dim map() As Byte, grid() As Byte, LcellsA() As Long, nrcells As Long
  202. Dim LcellsB() As Long, LcellsC() As Byte
  203. Dim mapB() As Byte, getout As Byte, CanDraw As Boolean, PatSave() As Long, nrSave As Long
  204. Private Sub Command1_Click()
  205. Dim i As Long, j As Long, number As Long, k As Long, gen As Long, cells As Long
  206. Dim neighbours As Byte, numberB As Long
  207. Dim iMinus As Long, iPlus As Long, jMinus As Long, jPlus As Long
  208. If PatEditor.loaded = True Then
  209. PatEditor.Command2_Click
  210. Unload PatEditor
  211. End If
  212. cmdRefresh.Enabled = False
  213. Command3.Enabled = False
  214. Command2.Enabled = False
  215. cmdStop.Enabled = False
  216. Command6.Enabled = False
  217. nrSave = 0
  218. Bar1.SimpleText = "Counting the cells..."
  219. On Error GoTo out
  220. getout = 0
  221. CanDraw = False
  222. ReDim map(-oriz To 2 * oriz, -vert To 2 * vert) As Byte
  223. ReDim mapB(-oriz To 2 * oriz, -vert To 2 * vert) As Byte
  224. ReDim grid(-oriz To 2 * oriz, -vert To 2 * vert) As Byte
  225. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
  226. For i = Form1.ScaleLeft To -Form1.ScaleLeft
  227.     For j = Form1.ScaleTop To -Form1.ScaleTop
  228.         iMinus = i - 1
  229.         iPlus = i + 1
  230.         jMinus = j - 1
  231.         jPlus = j + 1
  232.         If Form1.Point(i, j) = vbWhite Then
  233.             ReDim Preserve PatSave(1 To 2, nrSave) As Long
  234.             PatSave(1, nrSave) = i
  235.             PatSave(2, nrSave) = j
  236.             nrSave = nrSave + 1
  237.             map(i, j) = 1
  238.             ReDim Preserve LcellsA(1 To 2, number + 9) As Long
  239.             If grid(i, j) = 0 Then
  240.             grid(i, j) = 1
  241.             number = number + 1
  242.             LcellsA(1, number) = i
  243.             LcellsA(2, number) = j
  244.             End If
  245.             
  246.             If grid(iPlus, j) = 0 Then                         '1
  247.                 grid(iPlus, j) = 1
  248.                 number = number + 1
  249.                 LcellsA(1, number) = iPlus
  250.                 LcellsA(2, number) = j
  251.             End If
  252.             
  253.             If grid(iPlus, jPlus) = 0 Then                      '2
  254.                 grid(iPlus, jPlus) = 1
  255.                 number = number + 1
  256.                 LcellsA(1, number) = iPlus
  257.                 LcellsA(2, number) = jPlus
  258.             End If
  259.             
  260.             If grid(iPlus, jMinus) = 0 Then                       '3
  261.                 number = number + 1
  262.                 grid(iPlus, jMinus) = 1
  263.                 LcellsA(1, number) = iPlus
  264.                 LcellsA(2, number) = jMinus
  265.             End If
  266.             
  267.             If grid(i, jPlus) = 0 Then                            '4
  268.                 number = number + 1
  269.                 grid(i, jPlus) = 1
  270.                 LcellsA(1, number) = i
  271.                 LcellsA(2, number) = jPlus
  272.             End If
  273.             
  274.             If grid(i, jMinus) = 0 Then                             '5
  275.                 number = number + 1
  276.                 grid(i, jMinus) = 1
  277.                 LcellsA(1, number) = i
  278.                 LcellsA(2, number) = jMinus
  279.             End If
  280.             
  281.             If grid(iMinus, j) = 0 Then                             '6
  282.                 number = number + 1
  283.                 grid(iMinus, j) = 1
  284.                 LcellsA(1, number) = iMinus
  285.                 LcellsA(2, number) = j
  286.             End If
  287.             
  288.             If grid(iMinus, jPlus) = 0 Then                         '7
  289.                 number = number + 1
  290.                 grid(iMinus, jPlus) = 1
  291.                 LcellsA(1, number) = iMinus
  292.                 LcellsA(2, number) = jPlus
  293.             End If
  294.             
  295.             If grid(iMinus, jMinus) = 0 Then                         '8
  296.                 number = number + 1
  297.                 grid(iMinus, jMinus) = 1
  298.                 LcellsA(1, number) = iMinus
  299.                 LcellsA(2, number) = jMinus
  300.             End If
  301.             
  302.          End If
  303.     Next j
  304. Next i
  305. ReDim grid(-oriz To 2 * oriz, -vert To 2 * vert) As Byte
  306. Bar1.SimpleText = "Life goes on !"
  307. cmdStop.Enabled = True
  308. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
  309. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
  310. DoEvents
  311. k = k + 1
  312. cells = 0
  313. For nrcells = 1 To number
  314. i = LcellsA(1, nrcells)
  315. j = LcellsA(2, nrcells)
  316.         iMinus = i - 1
  317.         iPlus = i + 1
  318.         jMinus = j - 1
  319.         jPlus = j + 1
  320.         neighbours = map(iPlus, j) + map(iPlus, jPlus) + map(iPlus, jMinus) + map(i, jPlus) + _
  321.                      map(i, jMinus) + map(iMinus, j) + map(iMinus, jPlus) + map(iMinus, jMinus)
  322.         
  323.         '------------------------------------------------------------------------------------------------------
  324.         If (neighbours < 2 Or neighbours > 3) And map(i, j) = 1 Then
  325.             Form1.PSet (i, j), BackColor
  326.             mapB(i, j) = 0
  327.         ElseIf (neighbours = 3 And map(i, j) = 0) Or ((neighbours = 2 Or neighbours = 3) And map(i, j) = 1) Then
  328.             If map(i, j) = 0 Then
  329.             Form1.PSet (i, j), vbWhite     'By including this line in an "If...End If" block I gain a little
  330.             End If                         '(or more,depends on the pattern) speed, but some cells will not
  331.             mapB(i, j) = 1                 'be redrawn if the form is minimized or cover by other windows
  332.             cells = cells + 1              'during the simulation.
  333.             ReDim Preserve LcellsB(1 To 2, numberB + 9) As Long
  334. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
  335.             If grid(i, j) = 0 Then
  336.                 grid(i, j) = 1
  337.                 numberB = numberB + 1
  338.                 LcellsB(1, numberB) = i
  339.                 LcellsB(2, numberB) = j
  340.             End If
  341.             
  342.             If grid(iPlus, j) = 0 Then                         '1
  343.                 grid(iPlus, j) = 1
  344.                 numberB = numberB + 1
  345.                 LcellsB(1, numberB) = iPlus
  346.                 LcellsB(2, numberB) = j
  347.             End If
  348.             
  349.             If grid(iPlus, jPlus) = 0 Then                     '2
  350.                 grid(iPlus, jPlus) = 1
  351.                 numberB = numberB + 1
  352.                 LcellsB(1, numberB) = iPlus
  353.                 LcellsB(2, numberB) = jPlus
  354.             End If
  355.             
  356.             If grid(iPlus, jMinus) = 0 Then                     '3
  357.                 numberB = numberB + 1
  358.                 grid(iPlus, jMinus) = 1
  359.                 LcellsB(1, numberB) = iPlus
  360.                 LcellsB(2, numberB) = jMinus
  361.             End If
  362.             
  363.             If grid(i, jPlus) = 0 Then                         '4
  364.                 numberB = numberB + 1
  365.                 grid(i, jPlus) = 1
  366.                 LcellsB(1, numberB) = i
  367.                 LcellsB(2, numberB) = jPlus
  368.             End If
  369.             
  370.             If grid(i, jMinus) = 0 Then                        '5
  371.                 numberB = numberB + 1
  372.                 grid(i, jMinus) = 1
  373.                 LcellsB(1, numberB) = i
  374.                 LcellsB(2, numberB) = jMinus
  375.             End If
  376.             
  377.             If grid(iMinus, j) = 0 Then                        '6
  378.                 numberB = numberB + 1
  379.                 grid(iMinus, j) = 1
  380.                 LcellsB(1, numberB) = iMinus
  381.                 LcellsB(2, numberB) = j
  382.             End If
  383.             
  384.             If grid(iMinus, jPlus) = 0 Then                    '7
  385.                 numberB = numberB + 1
  386.                 grid(iMinus, jPlus) = 1
  387.                 LcellsB(1, numberB) = iMinus
  388.                 LcellsB(2, numberB) = jPlus
  389.             End If
  390.             
  391.             If grid(iMinus, jMinus) = 0 Then                   '8
  392.                 numberB = numberB + 1
  393.                 grid(iMinus, jMinus) = 1
  394.                 LcellsB(1, numberB) = iMinus
  395.                 LcellsB(2, numberB) = jMinus
  396.             End If
  397. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
  398.         End If
  399. Next nrcells
  400. For nrcells = 1 To number
  401. i = LcellsA(1, nrcells)
  402. j = LcellsA(2, nrcells)
  403. map(i, j) = mapB(i, j)
  404. Next nrcells
  405. For nrcells = 1 To numberB
  406. i = LcellsB(1, nrcells)
  407. j = LcellsB(2, nrcells)
  408. grid(i, j) = 0
  409. Next nrcells
  410. LcellsA = LcellsB
  411. Text1.Text = k
  412. Label1.Caption = cells
  413. number = numberB
  414. numberB = 0
  415. Loop Until getout = 1
  416.     If Err.number <> 0 Then
  417.     Bar1.SimpleText = "RED ALERT ! The cells have tried to escape from the grid !"
  418.     getout = 1
  419.     CanDraw = True
  420.     cmdRefresh.Enabled = True
  421.     Command3.Enabled = True
  422.     Command2.Enabled = True
  423.     Command6.Enabled = True
  424.     End If
  425. End Sub
  426. Private Sub cmdRefresh_Click()
  427.     getout = 1
  428.     CanDraw = True
  429.     Form1.Cls
  430. End Sub
  431. Private Sub Command2_Click()
  432. Dim fil As String, i As Long
  433. On Error GoTo out
  434. SaveDialog.ShowSave
  435. fil = SaveDialog.FileName
  436. Open fil For Output As #1
  437.     Print #1, "Save by Bogdan's ""Conway 's Game of Life"""
  438.     Print #1, "Version 1.0.0"
  439.     For i = 0 To nrSave - 1
  440.     Print #1, PatSave(1, i) & " " & PatSave(2, i)
  441.     Next i
  442. Close 1#
  443. out: Exit Sub
  444. End Sub
  445. Private Sub Command3_Click()
  446. cmdStop_Click
  447. cmdRefresh_Click
  448. Dim x As String, y As String, a As String, fis As String, desp As Long
  449. Dim x1 As Long, y1 As Long
  450. On Error GoTo out
  451. ChDir App.Path & "\Life"
  452. Dialog.ShowOpen
  453. fis = Dialog.FileName
  454. Open fis For Input As #1
  455.         Line Input #1, a
  456.         Line Input #1, a
  457.         Do While Not EOF(1)
  458.         Line Input #1, a
  459.         desp = InStr(1, a, " ", vbTextCompare)
  460.         x = Left(a, desp)
  461.         y = Right(a, Len(a) - desp)
  462.         x1 = CInt(x)
  463.         y1 = CInt(y)
  464.         Form1.PSet (x1, y1), vbWhite
  465.         Loop
  466.         Close #1
  467. Exit Sub
  468. out: Close #1
  469. End Sub
  470. Private Sub cmdStop_Click()
  471.     cmdRefresh.Enabled = True
  472.     Command3.Enabled = True
  473.     Command2.Enabled = True
  474.     Command6.Enabled = True
  475.     getout = 1
  476.     CanDraw = True
  477.     Bar1.SimpleText = "All cells were frozen !"
  478. End Sub
  479. Private Sub Command4_Click()
  480. Dim msg
  481. msg = MsgBox("LIFE is like a box of chocolates; you never know what you gonna get ! :)", vbInformation, "The Most Important Tip of All")
  482. End Sub
  483. Private Sub Command5_Click()
  484. Dim msg
  485. msg = MsgBox("Programmed by Lucian Bogdan Cristache" & vbCrLf & "        bogcrist@pcnet.ro", vbInformation, "About this LIFE")
  486. End Sub
  487. Private Sub Command6_Click()
  488. PatEditor.Show
  489. End Sub
  490. Private Sub Form_Load()
  491. oriz = Form1.ScaleWidth
  492. vert = Form1.ScaleHeight
  493. Option1.Value = True
  494. CanDraw = True
  495. End Sub
  496. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  497. If Button = 1 Then
  498.     Form1.ForeColor = vbWhite
  499. ElseIf Button = 2 Then
  500.     Form1.ForeColor = vbBlack
  501. End If
  502. If CanDraw = True Then
  503. drawcell = 1
  504. xx = x
  505. yy = y
  506. Form1.PSet (x, y)
  507. End If
  508. End Sub
  509. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  510. If CanDraw = True Then
  511. If drawcell Then Line (xx, yy)-(x, y)
  512. xx = x
  513. yy = y
  514. End If
  515. End Sub
  516. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  517. drawcell = 0
  518. Form1.ForeColor = vbWhite
  519. End Sub
  520. Private Sub Form_Unload(Cancel As Integer)
  521. cmdStop_Click
  522. Unload PatEditor
  523. Set Form1 = Nothing
  524. End Sub
  525. Private Sub Option1_Click()
  526. Form1.Refresh
  527. Form1.ScaleLeft = -436
  528. Form1.ScaleTop = -336
  529. Form1.ScaleWidth = oriz
  530. Form1.ScaleHeight = vert
  531. Form1.DrawWidth = 1
  532. End Sub
  533. Private Sub Option2_Click()
  534. Form1.Refresh
  535. Form1.ScaleLeft = -218
  536. Form1.ScaleTop = -168
  537. Form1.ScaleWidth = oriz / 2
  538. Form1.ScaleHeight = vert / 2
  539. Form1.DrawWidth = 2
  540. End Sub
  541.